<?php
// +----------------------------------------------------------------------
// | 手机短信
// +----------------------------------------------------------------------
namespace app\app\controller\soft;
use app\app\Appbase;
use base\service\MsgApi;

class Msg extends Appbase
{
	
	/**
	*发送短信
	* /app/soft/msg/send
	* 需要登录 
	* @is_need_login false
	*/
	public function send($phone,$type=0){
		if( !trim($phone) ){
			return $this->ReError("请输入手机号！");
		}
		if( preg_match("/^1[3456789]\d{9}$/", $phone) == 0 ){
			return $this->ReError("请输入正确的手机号码！");
		}
		try {
			//发送
			$msgapi = new MsgApi;
			$res = $msgapi->send($phone);
			if(!$res){
				return $this->ReError( $msgapi->errorInfo ); 
			}
			return $this->ReSucess("已发送");	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	/**
	* 效验手机code
	* /app/soft/msg/verifiCode
	* 需要登录 
	* @is_need_login false
	*/
	public function verifiCode($phone,$code=0){
		if( !trim($phone) ){
			return $this->ReError("请输入手机号！");
		}
		if( preg_match("/^1[3456789]\d{9}$/", $phone) == 0 ){
			return $this->ReError("请输入正确的手机号码！");
		}
		try {
			//发送
			$msgapi = new MsgApi;
			if( !$res = $msgapi->verifyCode($phone,$code) ){
				return $this->ReError( $msgapi->errorInfo ); 
			}
			return $this->ReSucess( md5($code) );	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
}
